<?php

include_once 'Room.php';

class RoomGroup {

    /**
     * @access public
     * @var Room[]
     */
    public $Room;

    public function RoomGroup($rooms= NULL, $count=0) {
        for ($index = 1; $index <= $count; $index++) {
            if (gettype($rooms[$index]) !== "undefined" &&
                    gettype($rooms[$index]) !== "null") {
                if (gettype($rooms[$index]) !== "object") {
                    $this->Room[$index] = new Room();
                    $this->Room[$index]->numberOfAdults =
                            $rooms[$index]["adultsCount"];
                    $this->Room[$index]->numberOfChildren =
                            $rooms[$index]["childrenCount"];
                    for($childIndex = 0;
                    $childIndex < $this->Room[$index]->numberOfChildren;
                    $childIndex++)
                    {
                        $this->Room[$index]->childAges[$childIndex]=
                                $rooms[$index]["children".($childIndex+1)];
                    }
                } else {
                    break;
                }
            }
        }
    }

	public function getRoomGroupRest() {
        $result = array();
        for ($i = 0; $i < count($this->Room); $i++) {
            $result ["room" . ($i + 1)] = $this->Room[$i + 1]->numberOfAdults;
            for ($j = 0; $j < count($this->Room[$i + 1]->childAges); $j++) {
                $result ["room" . ($i + 1)] .= "," . $this->Room[$i + 1]->childAges[$j];
            }
        }
        return $result;
    }
}